﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EPiServer.ServiceLocation;
using Newtonsoft.Json;

namespace EPiBoost.Core.CustomProperties.EnumSelector
{
	[ServiceConfiguration(typeof (JsonConverter))]
	public class SelectedEnumStringConverter : JsonConverter
	{
		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			string json = value.ToString();
			writer.WriteValue(json);
		}

		public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
		{
			return existingValue.ToString();
		}

		public override bool CanConvert(Type objectType)
		{
			if(objectType.Name.StartsWith("SelectedEnumCollection"))
			{
				return true;
			}
			return false;
		}
	}
	 
}
